package edu.hcmus.sow.dao;

import edu.hcmus.sow.domain.File;

import java.util.List;

import javax.persistence.NoResultException;

import org.hibernate.Query;
import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage File entities.
 * 
 */
@Repository("FileDAO")
@Transactional
public class FileDAOImpl extends AbstractHibernateDAO<File, Integer> implements FileDAO {

   public FileDAOImpl() {
      super();
   }

   @Transactional
   @SuppressWarnings("unchecked")
   public List<File> findByName(String fileName) throws DataAccessException {
      List<File> files = null;
      try {
         Query query = getSession().createQuery("select myFile from File myFile where Name := fileName");
         files = query.list();
      } catch (NoResultException e) {
         return null;
      }
      return files;
   }

}
